<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="css/mui.min.css" rel="stylesheet" />
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<a id="search" class="mui-icon mui-icon mui-icon-right-nav mui-pull-right" style="font-size: 16px;line-height: 25px;">搜索</a>
			<h1 class="mui-title">添加好友</h1>
		</header>

		<div class="mui-content">
			<div class="mui-input-row">
				<input id="friendName" type="text" class="mui-input-clear" placeholder="搜索好友">
			</div>

		</div>

		<script src="js/mui.min.js"></script>
		<script src="js/common.js"></script>
		<script type="text/javascript">
			mui.init();

			mui.plusReady(function() {

				var friendName = document.getElementById("friendName");
				friendName.value = "";
				
				var search = document.getElementById("search");
				search.addEventListener("tap", function() {
					// 提交请求
					mui.ajax(config.SERVER_URL + 'user/username', {
						data: {
							username: friendName.value
						},
						dataType: 'json',
						type: 'post',
						timeout: 10000,
						headers: {
							'Content-Type': 'application/json'
						},
						success: function(result) {
							console.log("查询结果: " + JSON.stringify(result));
							if(result.success) {
								mui.openWindow({
									url: "search-friend-result.html",
									id: "search-friend-result",
									extras: {
										friend: result.data
									}
								});
							} else {
								mui.alert(result.msg);
							}
						}
					});
					
				});
			});
		</script>
	</body>

</html>